<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<script>
description('Checks incomplete datetime formats are rejected.');

var input = document.createElement('input');
input.type = 'time';
document.body.appendChild(input);

function setDateTimeFormat(pattern) {
    var value = input.value;
    getElementByPseudoId(internals.shadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
    input.value = ''; // Updates the element for new format
    input.value = value;
}

input.value = '23:59:01.234';

debug('Valid format');
setDateTimeFormat('ss:mm:hh a');
shouldBeEqualToString('getUserAgentShadowTextContent(input)', '01.234:59:11 PM');
setDateTimeFormat('ss:mm:HH');
shouldBeEqualToString('getUserAgentShadowTextContent(input)', '01.234:59:23');
setDateTimeFormat('ss:mm:HH a');
shouldBeEqualToString('getUserAgentShadowTextContent(input)', '01.234:59:23 PM');

debug('Invalid format, fallback to HH:mm:ss');
setDateTimeFormat('HH');
shouldBeEqualToString('getUserAgentShadowTextContent(input)', '23:59:01.234');
setDateTimeFormat('mm:ss');
shouldBeEqualToString('getUserAgentShadowTextContent(input)', '23:59:01.234');
setDateTimeFormat('hh:mm:ss');
shouldBeEqualToString('getUserAgentShadowTextContent(input)', '23:59:01.234');

</script>
</body>
</html>
